package recycle.impl;

import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import recycle.dao.TradingrecordMapper;
import recycle.pojo.Hottradingrecord;
import recycle.dao.HottradingrecordMapper;
import java.io.Serializable;
import java.util.List;
import java.util.Map;

import recycle.pojo.Tradingrecord;
import recycle.utils.Page;
import javax.annotation.Resource;
import recycle.vo.HottradingrecordParam;
import recycle.service.HottradingrecordService;
/**
* 描述：热门交易记录表 服务实现层接口
* @author 孙冉
* @date 2019/07/22
*/
@Service
public class HottradingrecordServiceImpl implements HottradingrecordService{
	@Resource
	private HottradingrecordMapper hottradingrecordMapper;

	@Resource
	private TradingrecordMapper tradingrecordMapper;
 	
 	/**
    * 描述：根据Id获取Hottradingrecord对象
    * @param id
    */
    public Hottradingrecord findById(Serializable hotRecordId){
    	return hottradingrecordMapper.findById(hotRecordId);
    }
    /**
    * 描述：获取所有的Hottradingrecord对象
    */
    public List<Hottradingrecord> findAll(){
    	return hottradingrecordMapper.findAll();
    }

	/**
    * 描述：新增保存Hottradingrecord对象
    */
    public int save(Hottradingrecord hottradingrecord){
    	return  hottradingrecordMapper.save(hottradingrecord);
    }

	/**
    * 描述：根据Id删除Hottradingrecord对象
    * @param id
    */
    public int delete(Serializable hotRecordId){
    	return  hottradingrecordMapper.delete(hotRecordId);
    }
	
	/**
    * 描述：更新Hottradingrecord对象
    */
    public int update(Hottradingrecord hottradingrecord){
    	return  hottradingrecordMapper.update(hottradingrecord);
    }
    
    /**
     * 根据不确定的条件，动态查询
     */
    public List<Hottradingrecord> query(HottradingrecordParam param){
    	return  hottradingrecordMapper.query(param);
    }
    
    /**
     * 根据不确定的条件，动态分页查询
     */
    public Page queryByPage(HottradingrecordParam param){
    	Page page = new Page();
    	if(param.isPage()){
			int totalCount = hottradingrecordMapper.getCount(param);
			int totalPageCount = (totalCount-1)/page.getPageSize()+1;
			if(param.getPageIndex()<1){
				param.setPageIndex(1);
			}else if(param.getPageIndex()>totalPageCount){
				param.setPageIndex(totalPageCount);
			}
			List list = hottradingrecordMapper.query(param);

			page.setTotalCount(totalCount);
			page.setTotalPageCount(totalPageCount);
    		page.setPageNo(param.getPageIndex());
    		page.setPageSize(param.getSize());
			page.setList(list);
		}
    	return page;
    	
    }

	@Override
	@Scheduled(cron = "00 00 00 * * *")
	public int saveAppleTrandingrecord() {
    	int count = 0;
		List<Tradingrecord> trList = tradingrecordMapper.selectAppleTrandingrecord();
		for (int i = 0;i<trList.size();i++){
			Tradingrecord tr = trList.get(i);
			Hottradingrecord hr = new Hottradingrecord();
			hr.setCustomerId(tr.getCustomerId());
			hr.setHotRecordId(tr.getRecordId());
			hr.setModifiedTime(tr.getModifiedTime());
			hr.setHotRecordId(tr.getRecordId());
			hr.setOrderId(tr.getOrderId());
			hr.setOrderStatus(tr.getOrderStatus());
			hr.setOrderMoney(tr.getOrderMoney());
			hr.setPayTime(tr.getPayTime());
			hr.setRecycleMethod(tr.getRecycleMethod());
			hr.setOther1(tr.getOther1());
			hr.setOther2(tr.getOther2());
			if(hottradingrecordMapper.save(hr)>0){
				count++;
			}
		}
		return count;
	}

	@Override
	@Scheduled(cron = "00 00 00 * * *")
	public int saveHuaWeiTrandingrecord() {
    	int count = 0;
		List<Tradingrecord> trList = tradingrecordMapper.selectHuaWeiTrandingrecord();
		for (int i = 0;i<trList.size();i++){
			Tradingrecord tr = trList.get(i);
			Hottradingrecord hr = new Hottradingrecord();
			hr.setCustomerId(tr.getCustomerId());
			hr.setHotRecordId(tr.getRecordId());
			hr.setModifiedTime(tr.getModifiedTime());
			hr.setHotRecordId(tr.getRecordId());
			hr.setOrderId(tr.getOrderId());
			hr.setOrderStatus(tr.getOrderStatus());
			hr.setOrderMoney(tr.getOrderMoney());
			hr.setPayTime(tr.getPayTime());
			hr.setRecycleMethod(tr.getRecycleMethod());
			hr.setOther1(tr.getOther1());
			hr.setOther2(tr.getOther2());
			if(hottradingrecordMapper.save(hr)>0){
				count++;
			}
		}
		return count;
	}

	@Override
	@Scheduled(cron = "00 00 00 * * *")
	public int saveXiaoMiTrandingrecord() {
		int count = 0;
		List<Tradingrecord> trList = tradingrecordMapper.selectXiaoMiTrandingrecord();
		for (int i = 0;i<trList.size();i++){
			Tradingrecord tr = trList.get(i);
			Hottradingrecord hr = new Hottradingrecord();
			hr.setCustomerId(tr.getCustomerId());
			hr.setHotRecordId(tr.getRecordId());
			hr.setModifiedTime(tr.getModifiedTime());
			hr.setHotRecordId(tr.getRecordId());
			hr.setOrderId(tr.getOrderId());
			hr.setOrderStatus(tr.getOrderStatus());
			hr.setOrderMoney(tr.getOrderMoney());
			hr.setPayTime(tr.getPayTime());
			hr.setRecycleMethod(tr.getRecycleMethod());
			hr.setOther1(tr.getOther1());
			hr.setOther2(tr.getOther2());
			if(hottradingrecordMapper.save(hr)>0){
				count++;
			}
		}
		return count;
	}
}
